{% extends "pretixcontrol/items/base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% load eventsignal %}
{% load eventurl %}
{% block title %}{% trans "Voucher" %}{% endblock %}
{% block inside %}
    <nav id="event-nav" class="header-nav">
        <div class="navigation">
            <div class="navigation-title">
                <h1>{% trans "Voucher" %}</h1>
            </div>
            {% include "pretixcontrol/event/component_link.html" %}
        </div>
    </nav>
    {% if voucher.redeemed %}
        <div class="alert alert-warning">
            {% trans "This voucher already has been used. It is not recommended to modify it." %}
            <ul>
            {% for order in voucher.distinct_orders %}
                <li><a href="{% url "control:event.order" event=request.event.slug organizer=request.event.organizer.slug code=order.code %}">
                    {% blocktrans with code=order.code %}Order {{ code }}{% endblocktrans %}
                </a></li>
            {% endfor %}
            </ul>
        </div>
    {% endif %}
    <form action="" method="post" class="form-horizontal">
        {% csrf_token %}
        {% bootstrap_form_errors form %}
        <div class="row">
            <div class="col-xs-12 col-lg-10">
                <fieldset>
                    <legend>{% trans "Voucher details" %}</legend>
                    {% bootstrap_field form.code layout="control" %}
                    {% if voucher.pk %}
                        {% if not request.event.has_subevents or voucher.subevent %}
                            <div class="form-group">
                                <label class="col-md-3 control-label" for="id_url">{% trans "Voucher link" %}</label>
                                <div class="col-md-9">
                                    <input type="text" name="url"
                                            value="{% abseventurl request.event "presale:event.redeem" %}?voucher={{ voucher.code|urlencode }}{% if voucher.subevent_id %}&subevent={{ voucher.subevent_id }}{% endif %}"
                                            class="form-control"
                                            id="id_url" readonly>
                                </div>
                            </div>
                        {% endif %}
                    {% endif %}
                    {% bootstrap_field form.max_usages layout="control" %}
                    {% bootstrap_field form.valid_until layout="control" %}
                    {% bootstrap_field form.itemvar layout="control" %}
                    <div class="form-group">
                        <label class="col-md-3 control-label" for="id_tag">{% trans "Price effect" %}</label>
                        <div class="col-md-5">
                            {% bootstrap_field form.price_mode show_label=False form_group_class="" %}
                        </div>
                        <div class="col-md-4">
                            {% bootstrap_field form.value show_label=False form_group_class="" %}
                        </div>
                    </div>
                    <div class="form-group">
                        <div class="col-md-9 col-md-offset-3">
                            <div class="controls">
                                <div class="alert alert-info">
                                    {% blocktrans trimmed %}
                                        If you choose "any product" for a specific quota and choose to reserve quota for this
                                        voucher above, the product can still be unavailable to the voucher holder if another quota
                                        associated with the product is sold out!
                                    {% endblocktrans %}
                                </div>
                            </div>
                        </div>
                    </div>
                    {% if form.subevent %}
                        {% bootstrap_field form.subevent layout="control" %}
                    {% endif %}
                    {% if "seat" in form.fields %}
                        {% bootstrap_field form.seat layout="control" %}
                    {% endif %}
                </fieldset>
                <fieldset>
                    <legend>{% trans "Advanced settings" %}</legend>
                    {% bootstrap_field form.block_quota layout="control" %}
                    {% bootstrap_field form.allow_ignore_quota layout="control" %}
                    {% bootstrap_field form.budget addon_after=request.event.currency layout="control" %}
                    {% bootstrap_field form.tag layout="control" %}
                    {% bootstrap_field form.comment layout="control" %}
                    {% bootstrap_field form.show_hidden_items layout="control" %}
                </fieldset>
                {% eventsignal request.event "pretix.control.signals.voucher_form_html" form=form %}
            </div>
            <div class="col-xs-12 col-lg-2">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            {% trans "Voucher history" %}
                        </h3>
                    </div>
                    {% include "pretixcontrol/includes/logs.html" with obj=voucher %}
                </div>
            </div>
        </div>
        <div class="form-group submit-group">
            <button type="submit" class="btn btn-primary btn-save">
                {% trans "Save" %}
            </button>
        </div>
    </form>
{% endblock %}
